<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    .box{width:100px;height:100px;background: red;position: absolute;left:0;top:0;}
  </style>
</head>
<body>
  <div class="box"></div>
</body>
<script>
  var box = document.querySelector(".box")

  document.onkeydown = function(eve){
    var e = eve || window.event;
    var keyCode = e.keyCode || e.which;
    if(keyCode === 37){
      // 将元素的css属性设置为：先获取当前值 - 步长 + 单位
      box.style.left = box.offsetLeft - 100 + "px";
    }
    if(keyCode === 38){
      box.style.top = box.offsetTop - 100 + "px";
    }
    if(keyCode === 39){
      box.style.left = box.offsetLeft + 100 + "px";
    }
    if(keyCode === 40){
      box.style.top = box.offsetTop + 100 + "px";
    }
  }

</script>
</html>